//
//  ZTListQueryParam.m
//  app 列表类查询参数封装
//
//  Created by bigknife on 14/11/2.
//  Copyright (c) 2014年 zzt. All rights reserved.
//

#import "VMCListQueryParam.h"

const QueryOrder kQueryOrderAsc = @"asc";
const QueryOrder kQueryOrderDesc = @"desc";

@implementation VMCListQueryParam
-(NSDictionary *)asDict{
    return [self asDictWithObject:nil forKey:nil];
}

-(NSDictionary *) asDictWithObject:(id)obj forKey:(id<NSCopying>)key
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    if (self.by) {
        [dict setObject:self.by forKey:@"by"];
    }
    if (self.order) {
        [dict setObject:self.order forKey:@"order"];
    }
    if (self.pageEnabled)
	{
        [dict setObject:[NSNumber numberWithBool:self.pageEnabled] forKey:@"pageEnabled"];
        [dict setObject:[NSNumber numberWithInteger:self.pageIndex] forKey:@"pageIndex"];
        [dict setObject:[NSNumber numberWithInteger:self.pageSize] forKey:@"pageSize"];
    }
    
    if (obj && key)
	{
        [dict setObject:obj forKey:key];
    }
    
    return  [NSDictionary dictionaryWithDictionary:dict];
}
-(NSDictionary *) asDictWithDictionary:(NSDictionary *)dictionary {
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    if (self.by) {
        [dict setObject:self.by forKey:@"by"];
    }
    if (self.order) {
        [dict setObject:self.order forKey:@"order"];
    }
    if (self.pageEnabled)
	{
        [dict setObject:[NSNumber numberWithBool:self.pageEnabled] forKey:@"pageEnabled"];
        [dict setObject:[NSNumber numberWithInteger:self.pageIndex] forKey:@"pageIndex"];
        [dict setObject:[NSNumber numberWithInteger:self.pageSize] forKey:@"pageSize"];
    }
    
    if (dictionary) {
        [dict addEntriesFromDictionary:dictionary];
    }
    
    return  [NSDictionary dictionaryWithDictionary:dict];
}

@end
